package ie.defaoitigh;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MapToolsActivity extends Activity implements OnClickListener {
	GridReference source = new GridReference();
	GridReference dest = new GridReference();
	private EditText srcGridLetter;
	private EditText destGridLetter;
	private EditText longFrom;
	private EditText latFrom;
	private EditText longDest;
	private EditText latDest;
	private GridReference gridRefSource;
	private GridReference gridRefDest;
	private TextView bearingResult;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        

		
		
        setContentView(R.layout.main);
        Button submitButton = (Button) findViewById(R.id.submitButton);
        
        submitButton.setOnClickListener(this);
    }

	public void onClick(View arg0) {
		gridRefSource = new GridReference();
        gridRefDest = new GridReference();
		if(R.id.submitButton == arg0.getId()){
			
			longFrom = (EditText) findViewById(R.id.LongFrom);
			latFrom = (EditText) findViewById(R.id.LatFrom);
			longDest = (EditText) findViewById(R.id.LongDest);
			latDest = (EditText) findViewById(R.id.LatDest);
			bearingResult = (TextView) findViewById(R.id.ResultCompasBearing);
	        srcGridLetter = (EditText) findViewById(R.id.GridLetterFrom);
			destGridLetter = (EditText) findViewById(R.id.GridLetterDest);
			
			
			gridRefSource.setGridLetter(srcGridLetter.getText().toString().toUpperCase().getBytes());
			gridRefSource.setEasting(Integer.parseInt(longFrom.getText().toString()));
			gridRefSource.setNorthing(Integer.parseInt(latFrom.getText().toString()));
			
			
			gridRefDest.setGridLetter(destGridLetter.getText().toString().toUpperCase().getBytes());
			gridRefDest.setEasting(Integer.parseInt(longDest.getText().toString()));
			gridRefDest.setNorthing(Integer.parseInt(latDest.getText().toString()));
			
			bearingResult.setText(getString(R.string.resultTextField)+Double.toString(gridRefSource.getBearingFrom(gridRefDest)));
		}
		
	}
}